<?
echo '-----'.$_PERSO_NIV.'---<br>';

FUNCTION gen_terrain($ter2tmp,$ter_loc){
             //$ter2$tmp= TErrain id
//REQUIRE("ville_function.php");



$terrain=EXPLODE("/",$terrain2);

$terrain_x=1;
$terrain_y=1;
$continent='AA';


$query1="SELECT continent_".$ter2tmp." FROM acontient WHERE continent_id=1";
$resultat1=mysql_query($query1);
$tmp1=mysql_fetch_row($resultat1);
//echo "<BR>Def:$tmp1[0]<BR>";

$ressourse=EXPLODE("/",$tmp1[0]);
$nbr_ress=count($ressourse);

                    // echo $nbr_ress;
//Gestion aleatoire du terrain.
//*****************************
FOR ($i=0;$i<$nbr_ress;$i++){

     $var_tmp=EXPLODE("-",$ressourse[$i]);

    SWITCH ($var_tmp[0]){
        CASE 10:
             $total=0; $CHOIX=0;
             $ress_tmp=EXPLODE("*",$ressourse[$i]);
             
             FOR ($i2=1;$i2<count($ress_tmp);$i2++){

                 $var_tmp2=EXPLODE("-",$ress_tmp[$i2]);
                   //echo "/$ress_tmp[$i]/";
                 $rand=mt_rand(1,90);

                 IF ($rand>=$var_tmp2[3]){
                      $choix_resource[$total]=$i2;
                      $total++;
                  }//fin du IF ($rand<$var_tmp2[3]){
           }//Fin du   FOR ($i2=1;$i<count($ress_tmp);$i2++){

                //Calculer quel ressource doit etre chouisie, au hasard.
                $rand=mt_rand(1,$total);
                // echo "($rand)";
                //Prendre la resource qui est choisie.
              //echo "<BR>-$total- $ress_tmp[$rand]";
             $var_tmp2=EXPLODE("-",$ress_tmp[$rand]);

             $tmpx=randl();
             IF ($tmpx> $var_tmp2[1]){ $tmpx= $var_tmp2[1];}
              $var_tmp2[1]=$tmpx;

             $tmpx=randl();
             IF ($tmpx> $var_tmp2[2]){ $tmpx= $var_tmp2[2];}
              $var_tmp2[2]=$tmpx;
               $var_tmp2[3]= $var_tmp2[0];
              $var_tmp2[0]=10;
              $ressourse[$i]=IMPLODE("-",$var_tmp2);
             //echo "--$ressourse[$i]--";
        BREAK;

        DEFAULT:


             $tmpx=randl();
             IF ($tmpx>$var_tmp[1]){ $tmpx=$var_tmp[1];}
             $var_tmp[1]=$tmpx;
             
             $tmpx=randl();
             IF ($tmpx>$var_tmp[2]){ $tmpx=$var_tmp[2];}
             $var_tmp[2]=$tmpx;

             $ressourse[$i]=IMPLODE("-",$var_tmp);
                  BREAK;
   }//Fin du SWITCH
   



}//Fin du for



$tmpx=IMPLODE("+",$ressourse);
          //  echo "***$tmpx***";
RETURN $tmpx;


}//Fin de la fonction
FUNCTION randl(){

$rand=mt_rand(1,1000);
IF ($rand<50){ $rand2=0;}
ELSEIF ($rand>50 && $rand<100){ $rand2=1;}
ELSEIF ($rand>100 && $rand<200){ $rand2=2;}
ELSEIF ($rand>200 && $rand<600){ $rand2=3;}
ELSEIF ($rand>600 && $rand<950){ $rand2=4;}
ELSEIF ($rand>950){ $rand2=5;}

IF ($_PERSO_NIV<3 && $rand2==0){$rand2=1;}




RETURN $rand2;

}


?>
